package com.example.fp.zxd.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.fp.cgc.entity.PageCondition;
import com.example.fp.zxd.entity.Gzh;
import com.example.fp.cgc.entity.Type;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 说明: gzh表操作接口
 * 编写人: 主晓东
 * 编写时间: 2019-12-31
 * 修改时间:
 * 接口
 */
@Mapper
public interface GzhMapper extends BaseMapper<Gzh> {

    @Select("SELECT htype as name, count(*) as value FROM gzh group by htype")
    public List<Type> selectTypeList();

    @Select("select * from gzh")
    List<Gzh> selectallGzh();

    @Select("<script>" +
            "select * from gzh" +
            "            <if test=\"start!=null and size!=null\">\n" +
            "                limit #{start},#{size}\n" +
            "            </if>\n" +
            "</script>")
    List<Gzh> selectGzhListPage(PageCondition page);

    @Select("select count(*) from gzh")
    int selectgzhsum();

    @Select("select t.rn from (\n" +
            "    select *,row_number()\n" +
            "        over (order by id) rn from gzh) t\n" +
            " where t.id = #{id}")
    int getGzhIndex(int id);

    /**
     * @author 蔡
     * @since 2020-01-20
     */
    @Select("<script>" +
            "select count(*) from gzh" +
            "         <where>" +
            "            <if test=\"hname != null and hname != ''\">" +
            "                hname LIKE CONCAT('%',#{hname},'%')" +
            "            </if>" +
            "         </where>" +
            "</script>")
    int getGzhSizeByName(String hname);

    /**
     * @author 蔡
     * @since 2020-01-20
     */
    @Select("<script>" +
            "select * from gzh" +
            "         <where>" +
            "            <if test=\"hname != null and hname != ''\">" +
            "                hname LIKE CONCAT('%',#{hname},'%')" +
            "            </if>" +
            "         </where>" +
            "            <if test=\"start!=null and size!=null\">\n" +
            "                limit #{start},#{size}\n" +
            "            </if>\n" +
            "</script>")
    List<Gzh> selectSearchGzhListPage(PageCondition pageCondition);
}